package methodInvoke;

public class StaticDispatch {
    static abstract class Human{
    }
    static class Man extends Human{
    }
    public  void sayHello(Human human){
        System.out.println("human");
    };
    public  void sayHello(Man man){
        System.out.println("man");
    };

    /**
     *
     *    #10 = Methodref          #8.#37         // methodInvoke/StaticDispatch.sayHello:(LmethodInvoke/StaticDispatch$Human;)V
     *    #8 = Class              #36            // methodInvoke/StaticDispatch
     *    #36 = Utf8               methodInvoke/StaticDispatch
     *    #37 = NameAndType        #20:#21        // sayHello:(LmethodInvoke/StaticDispatch$Human;)V
     *    #20 = Utf8               sayHello
     *    #21 = Utf8               (LmethodInvoke/StaticDispatch$Human;)V
     *
     *     public static void main(java.lang.String[]);
     *     descriptor: ([Ljava/lang/String;)V
     *     flags: (0x0009) ACC_PUBLIC, ACC_STATIC
     *     Code:
     *       stack=2, locals=2, args_size=1
     *          0: new           #6                  // class methodInvoke/StaticDispatch$Man
     *          3: dup
     *          4: invokespecial #7                  // Method methodInvoke/StaticDispatch$Man."<init>":()V
     *          7: astore_1
     *          8: new           #8                  // class methodInvoke/StaticDispatch
     *         11: dup
     *         12: invokespecial #9                  // Method "<init>":()V
     *         15: aload_1
     *         16: invokevirtual #10                 // Method sayHello:(LmethodInvoke/StaticDispatch$Human;)V
     *         19: return
     *       LineNumberTable:
     *         line 51: 0
     *         line 58: 8
     *         line 59: 19
     *
     *
     *  注意这里#37 = NameAndType        #20:#21        // sayHello:(LmethodInvoke/StaticDispatch$Human;)V
     *
     *
     *
     * @param args
     */
    public static void main(String[] args) {
        //静态类型--------实际类型
        Human human = new Man();
        /**
         * 结果：
         * human
         * 分析:
         * 这里采用的是静态分派。根据静态类型来判定调用方法
         */
        new StaticDispatch().sayHello(human);
    }
}
